package writtenexamination.weimeng;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author cyt
 * @create 2020-10-11 下午 4:52
 */
public class Tc {
    public static void main(String[] args) {
        String[] ans = {"a", "a", "b", "b", "c"};
        Tc tc = new Tc();
        String[] strings = tc.countString(ans);
        for (String string : strings) {
            System.out.println(string);
        }
    }

    public String[] countString(String[] inputArray) {
        ArrayList<String> ans = new ArrayList<>();
        // write code here
        HashMap<String, Integer> map = new HashMap<>();
        for (String s : inputArray) {
            boolean containsKey = map.containsKey(s);
            if (containsKey) {
                ans.add(s);
                Integer integer = map.get(s);
                map.put(s, integer++);
            } else {
                map.put(s, 1);
            }
        }
        String[] res = new String[0];
        return ans.toArray(res);
    }

}
